package com.gtxc.kotlinmvvm.utlis;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.gtxc.kotlinmvvm.R;


public class DialogUtlis {

    public static Dialog dialogzwl(Context mcontext,int layoutID,int Gravity,int windowwidth,int windowheight  ){
        View view = LayoutInflater.from(mcontext).inflate(layoutID, null);

        final Dialog dialog =new Dialog(mcontext, R.style.Theme_Light_PayDialog);
        dialog.setContentView(view);
//        dialog.show();
        Window window = dialog.getWindow();
//        (Gravity.CENTER
        window.setGravity(Gravity);
        window.setWindowAnimations(R.style.AnimBottomOut); // 添加动画
        WindowManager.LayoutParams lp = window.getAttributes();
        if (windowwidth==1&&windowheight==1){
            lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        }else if (windowwidth==1&&windowheight==2){
            lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;
        }else if (windowwidth==2&&windowheight==1){
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        }else if (windowwidth==2&&windowheight==2){
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;
        }
        window.setAttributes(lp);
        dialog.setCanceledOnTouchOutside( true );//设置点击Dialog外部任意区域关闭Dialog
        return dialog;
    }

}
